package com.originskyseed.platform.user.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.user.i18n.UserResponseMsg;
import com.originskyseed.platform.user.model.SalesmanRelateLevelLog;
import com.originskyseed.platform.user.model.UserInfo;
import com.originskyseed.platform.user.service.ISalesmanRelateLevelLogService;
import com.originskyseed.platform.user.service.IUserInfoService;
import com.originskyseed.platform.user.vo.request.SalesmanRelateLevelLogRequestVO;

/**
 * 业务员关联等级调整信息Controller类（OSI_SALESMAN_RELATE_LEVEL_LOG）
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/salesmanRelateLevelLog")
@BaseLocaleResource(localeFileName = "i18n_user")
public class SalesmanRelateLevelLogController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(SalesmanRelateLevelLogController.class);

	@DubboReference
	private ISalesmanRelateLevelLogService salesmanRelateLevelLogService;

	@DubboReference
	private IUserInfoService userInfoService;

	/**
	 * 分页查询
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/salesmanRelateLevelLogList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<SalesmanRelateLevelLog>> salesmanRelateLevelLogList(HttpServletRequest request) {
		BaseResponseBody<BasePage<SalesmanRelateLevelLog>> result = null;
		try {
			// 请求对象
			SalesmanRelateLevelLogRequestVO requestVO = this.getParameterBean(SalesmanRelateLevelLogRequestVO.class);

			// 分页查询
			BasePage<SalesmanRelateLevelLog> page = new BasePage<SalesmanRelateLevelLog>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.salesmanRelateLevelLogService.selectListByPage(requestVO.toMap(), page);
			for (SalesmanRelateLevelLog salesmanRelateLevelLog : page.getResults()) {
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(salesmanRelateLevelLog.getBusinessId());
				if (userInfo != null) {
					salesmanRelateLevelLog.setBusinessAccount(userInfo.getAccount());
					salesmanRelateLevelLog.setBusinessName(userInfo.getName());
				}
			}
			result = new BaseResponseBody<BasePage<SalesmanRelateLevelLog>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_LIST_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<SalesmanRelateLevelLog>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), UserResponseMsg.DATA_LIST_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

}